<style>
    #inbox{
        height:calc(100vh - 55px);
        position: relative;
    }
    #inbox .layout-inbox{
        opacity: 0;
        height: calc(100% - 50px);
    }
</style>
<!--inbox-->
<link rel="stylesheet" href="/views/inbox/tmp.css">
<section id="inbox">
    <div class="breadcrumb">
        <span>Inbox</span>
        <i class="iconfont icon-get-email"></i>
    </div>
    <div class="layout-inbox feat-grid">
        <!-- allowOverflow auto-attached by option: west__showOverflowOnHover = true -->
        <div class="ui-layout-west">
            <!--站点/标题-->
            <div class="site-header fx-row-b" id="site-header">
                <span class="header-img"><img src="" alt=""></span>
                <!--选择框组件-->
                <div class="header-select" id="site_id">
                    <select name="site_id">

                    </select>
                </div>
                <h4 class="header-num">0</h4>
            </div>
            <!--search-->
            <div class="site-search fx-row-c">
                <div class="search-a fx-row-b">
                    <i class="iconfont icon-sousuo"></i>
                    <input type="text" name="search" placeholder="发件人名称、邮箱、邮件标题、TicketID">
                </div>
                <i class="iconfont icon-fanhui hide"></i>
            </div>
            <div class="site-search-result hide">
                <div class="list-title fx-row-b">
                    <span>Search Result</span>
                    <span data-name="title-num">0</span>
                </div>
                <div class="list-content" style="display: block;">
                    <section data-name="com-check" class="com-check"></section>
                </div>
            </div>
            <!--email-->
            <ul data-name="menuItem" class="site-email">
                <li id="search" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>Search Result</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="twentyFour" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>24 hours ago</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="twelve" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>12 hours ago</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="eight" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>8 hours ago</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="now" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>最新</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
            </ul>

        </div>

        <!--右侧-->
        <div class="ui-layout-east">
            <div class="order-no">
                <img src="/src/img/order-no.jpg" alt="">
                <h5>暂无订单数据</h5>
            </div>
            <ul class="order-header">
                <li class="box-list"></li>
            </ul>
            <ul class="order-box">
                <!--订单数据-->
            </ul>
        </div>

        <div class="ui-layout-center">
            <div class="mes-header">
                <span id="mes-header-box">
                    <!--<span class="email"><label></label></span>
                    <span class="ticket"><label>Ticket-SN：</label><span></span></span>
                    <span class="reply"><label>回复数：</label>0</span>
                    <span class="outAuthor"><label>销售：</label>{{nickname}}</span>
                    -->
                </span>
                <i class="back iconfont icon-xiangyou fold fold-z"></i>
            </div>
            <section class="mes-child-box">
                <div class="child-north">
                    <div class="mes-content">
                        <!--会话详情填充-->
                        <div class="mes-emmm">
                            <img src="/src/img/emmm.jpg" alt="">
                            <!--<h5 class="mt10">暂没有相关会话</h5>-->
                        </div>
                    </div>
                </div>
                <div class="child-center">
                    <div class="mes-send">
                        <!--<div class="send-title">
                            <p id="toggleAllPanes">45456</p>
                            <button id="btnReset">button</button>
                        </div>-->
                        <div id="editor-container"></div>
                    </div>
                </div>
            </section>

            <div class="mes-footer fx-row-b">
                <button type="button" id="send" class="btn-c c-pos">
                    <i class="send-animate"><span class="send-main"></span></i>
                    <span class="send-text">发送(Ctrl + Enter)</span>
                </button>
                <div>
                    <!--<button id="selTemplate" class="btn-d">选择模板</button>-->
                    <button id="staff" class="btn-a ml10">指派</button>
                    <button id="trash" class="btn-b ml10 hide">垃圾箱</button>
                </div>
            </div>
        </div>

    </div>
</section>

<!--template start-->
<!--header Site-->
<script id="inbox-site-list" type="text/html">
    <span class="header-img"><img src="{{data[0].logo_src}}" alt=""></span>
    <!--选择框组件-->
    <div class="header-select">
        <select name="site_id">
            {{each data as v i}}
            <option value="{{v.account_id}}" data-id="{{v.site_id}}" data-num="{{v.opened_cnt}}" data-img="{{v.logo_src}}">{{v.site_name}}</option>
            {{/each}}
        </select>
    </div>
    <h4 class="header-num">{{data[0].opened_cnt}}</h4>
</script>

<!--email-list <input type="checkbox" value="{{v.ticket_id}}">-->
<!--menu-->
<script id="inbox-site-email" type="text/html">
    {{each data as v i}}
    <div class="content-list fx-col-c">
        <div class="list-email">
            <label>
                <i data-name="checkStyle" class="check-box"></i>
                <input type="checkbox" value="{{v.ticket_id}}">
            </label>
            <span class="email-text">{{v.subject}}</span>
        </div>
        <div class="list-text">{{v.message_info}}</div>
    </div>
    {{/each}}
</script>
<!--email-list-title <span>{{$imports.hoursNum}}</span>-->
<script id="inbox-site-email-title" type="text/html">
    {{opened_cnt}}
</script>

<!--会话头部-->
<script type="text/html" id="inbox-talk-head">
    <span class="email"><label>{{receiver_email}}</label></span>
    <span class="ticket"><label>Ticket-SN：</label><span>{{ticket_sn}}</span></span>
    <span class="reply"><label>回复数：</label>{{reply_count}}</span>
    <span class="outAuthor"><label>销售：</label>{{nickname}}</span>
</script>

<!--会话模板-->
<script type="text/html" id="inbox-talk">
    {{each list as v i}}
    <div class="content-list clearfix {{v.is_user == 1 ? 'client' : 'user'}}">
        <div class="content-head">
            <i class="head-a"></i>
            <p>{{v.from_name}}</p>
        </div>
        <div class="content-detail">
            <div class="detail-header row">
                <div class="col-sm-12">{{subject}}</div>
                <div class="col-sm-12 tr">Sending Time: {{ v.create_time }}</div>
            </div>
            <div class="detail-text">
                {{if v.text_html}}
                {{@v.text_html}}
                {{else}}
                {{v.text_plain}}
                {{/if}}
            </div>
        </div>
    </div>
    {{/each}}
</script>

<!--erp订单列表模板-->
<script type="text/html" id="inbox-erp">
    {{each response as v i}}
    <li data-name="menuList" class="box-list">
        <!--基本订单信息-->
        <div data-name="menuTitle" class="box-title">
            <div class="row">
                <div class="col-sm-16"><label>订单号：</label><span class="label-text order"><a href="{{v.erp_order_href}}" target="_blank">{{v.order_sn}}</a></span></div>
                <div class="col-sm-8"><label>状态：</label><span class="label-text">{{v.order_status}}</span></div>
            </div>
            <div class="row">
                <div class="col-sm-16"><label>站点：</label><span class="label-text">{{v.site}}</span></div>
                <div class="col-sm-8"><label>物品数：</label><span class="label-text">{{v.GoodList.length}}</span></div>
            </div>
        </div>
        <div class="box-content" data-name="menuContent">
            <!--详细订单信息-->
            <div class="list-message">
                <div class="row">
                    <div class="col-sm-16"><label>下单时间：</label><span class="label-text" title="">{{v.AddTime}}</span></div>
                    <div class="col-sm-8"><label>是否争议：</label><span class="label-text" title="">{{v.IsDisputed}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>支付时间：</label><span class="label-text" title="">{{v.PayTime}}</span></div>
                    <div class="col-sm-8"><label>是否退款：</label><span class="label-text">{{v.RefundType}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>支付：</label><span class="label-text" title="">{{v.final_price}} ; {{v.FinalPrice}}</span></div>
                    <div class="col-sm-8"><label>运费：</label><span class="label-text">{{v.ShippingPrice}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>活动：</label><span class="label-text" title="">{{v.CActivePrice}}</span></div>
                    <div class="col-sm-8"><label>折扣：</label><span class="label-text">{{v.DiscountPrice}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>支付方式：</label><span class="label-text" title="">{{v.PayType}}</span></div>
                    <div class="col-sm-8"><label>币种：</label><span class="label-text">{{v.Currency.Name}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>配送：</label><span class="label-text">{{v.ShippingType}}</span></div>
                </div>
            </div>
            <!--订单商品列表-->
            <ul class="list-content">
                {{each v.GoodList as val index}}
                <li class="content-list">
                    <div class="list-text">
                        <div class="text-line row">
                            <div class="col-sm-16"><label>SPU：</label><span>{{val.SPU}}</span></div>
                            <div class="col-sm-8"><i class="line-status">{{val.Status}}</i></div>
                        </div>

                        <div class="text-line row">
                            <div class="col-sm-12"><label>单价：</label><span>{{val.Price}}</span></div>
                            <label class="col-sm-12 tr">
                                {{val.SKU}}
                            </label>
                        </div>
                        <div class="text-line row">
                            <div class="col-sm-16"><label>运单：</label><span>{{val.ExpressNo}}</span></div>
                        </div>
                    </div>
                    <!--<div class="list-img" style="background-image:url({{ 'http://pms-hk.aopcdn.com/orgin/' + val.ThumbnailsUrl + '?x-oss-process=image/resize,m_lfit,h_60,w_60' }})"></div>-->
                    <div class="list-img">
                        <img src="{{ 'https://pms-hk.aopcdn.com/orgin/' + val.ThumbnailsUrl + '?x-oss-process=image/resize,m_lfit,h_60,w_60' }}" alt="">
                    </div>
                </li>
                {{/each}}
            </ul>
        </div>
    </li>
    {{/each}}
</script>


<!--selectTmp-->
<script id="inbox-select-tmp" type="text/html">
    <div class="staff-box">
        <h4 class="box-title">
            请选择模板:
        </h4>
        <i class="box-close">&times;</i>
        <section class="com-select-floor">
            <div class="sel-item">
                <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="请选择"/>
                <input type="hidden" value="">
                <i class="sel-icon"></i>
            </div>
            <div class="sel-box"></div>
        </section>
    </div>
</script>

<script src="/src/lib/jquery-ui-latest.js"></script>
<script src="/src/lib/jquery.layout-1.3.0.rc30.80.js"></script>
<script>
    var options = [{
        value: 'zhinan',
        label: '指南',
        children: [{
            value: 'shejiyuanze',
            label: '设计原则',
            children: [{
                value: 'yizhi',
                label: '一致'
            }, {
                value: 'fankui',
                label: '反馈'
            }, {
                value: 'xiaolv',
                label: '效率'
            }, {
                value: 'kekong',
                label: '可控'
            }]
        }, {
            value: 'daohang',
            label: '导航',
            children: [{
                value: 'cexiangdaohang',
                label: '侧向导航'
            }, {
                value: 'dingbudaohang',
                label: '顶部导航'
            }]
        }]
    }, {
        value: 'zujian',
        label: '组件',
        children: [{
            value: 'basic',
            label: 'Basic',
            children: [{
                value: 'layout',
                label: 'Layout 布局'
            }, {
                value: 'color',
                label: 'Color 色彩'
            }, {
                value: 'typography',
                label: 'Typography 字体'
            }, {
                value: 'icon',
                label: 'Icon 图标'
            }, {
                value: 'button',
                label: 'Button 按钮'
            }]
        },{
            value: 'others',
            label: 'Others',
            children: [{
                value: 'dialog',
                label: 'Dialog 对话框'
            }, {
                value: 'tooltip',
                label: 'Tooltip 文字提示'
            }, {
                value: 'popover',
                label: 'Popover 弹出框'
            }, {
                value: 'card',
                label: 'Card 卡片'
            }, {
                value: 'carousel',
                label: 'Carousel 走马灯'
            }, {
                value: 'collapse',
                label: 'Collapse 折叠面板'
            }]
        }]
    }, {
        value: 'ziyuan',
        label: '资源',
        children: [{
            value: 'axure',
            label: 'Axure Components'
        }, {
            value: 'sketch',
            label: 'Sketch Templates'
        }, {
            value: 'jiaohu',
            label: '组件交互文档'
        }]
    }];
    $.extend(window.p,{
        //当前站点Id
        account_id:com.getCookie("account_id") ? com.getCookie("account_id") : para.user.account_ids[0],
        pageNum:20,
        quill:null,
        myLayout:null,
        selectStaff:null,
        selectTmp:null,
        now:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        eight:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        twelve:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        twentyFour:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        search:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        src:[
            //'/src/lib/jquery-ui-latest.js',
            //'/src/lib/jquery.layout-1.3.0.rc30.80.js',
            //'/src/component/quill/quill.min.js',
        ]
    });

    $(function(){
        initEvent();

        function initEvent(){
            //菜单Menu
            $(".site-email").comMenu();
            $(".order-box").comMenu();

            //初始化菜单选择组件(checked方法可返回所选择的邮件ticket数组)
            p.now.comCheck = $("#now").comCheck();
            p.eight.comCheck = $("#eight").comCheck();
            p.twelve.comCheck = $("#twelve").comCheck();
            p.twentyFour.comCheck = $("#twentyFour").comCheck();
            p.search.comCheck = $("#search").comCheck();

            //初始请求菜单数据
            if(p.urlPara){
                //如果有参数(from processed)
                reqTicket(p.urlPara);
                $(".icon-get-email,.site-email,.site-search").hide()
            }else{
                menuBox();
            }

            para.user.operation.trashbin && $("#trash").removeClass('hide');

            getSite();

            //菜单滚动异步处理
            $(".list-content").on("scroll",function(){
                var top = $(this).scrollTop();
                var scrollHeight = $(this)[0].scrollHeight;
                var docHeight = $(this).height();
                var name = '';
                //参数3: 滑动至尾部仅剩3条时触发异步请求
                if(top+docHeight >= (scrollHeight-70*3)){
                    name = $(this).closest("[data-name='menuList']").prop('id');
                    menuRequest({
                        hoursName:name,
                        init:false,
                    });
                }
            });

            //拉取邮件收件箱
            $(".icon-get-email").on('click',function(){
                app.ajax({
                    type:'post',
                    url:app.api('/api/mail/ownerRobot/' + para.token),
                    data:{
                        account_id:p.account_id,
                        admin_id:para.user.admin_id,
                        limit:10
                    },
                    success:function(res){
                        if(res.code == 0){
                            $.comMessage({
                                type:'success',
                                text:'收取成功！',
                            });
                            menuBox();
                        }else{
                            $.comMessage({
                                type:'warning',
                                text:res.msg,
                            });
                        }
                    }
                });
            });

            //选择人员指派
            $("#staff").on('click',function(){
                p.selectStaff = com.layerInsert(para.staffList,function(){
                    $("[data-name='staffListObj']").comSelect({
                        init:true,
                        search:true,
                        callback:function(val,text){
                            para.staffId = val;
                        }
                    });
                    //指派确定按钮
                    $(".staff-button").on("click",function(){
                        var w = $(".site-email").children('.active').prop('id');
                        var checkList = [];
                        p.urlPara ? checkList.push(p.urlPara) : checkList = p[w].comCheck.checked();
                        if(checkList.length < 1){
                            $.comMessage({
                                type:'prompt',
                                text:'请勾选邮件!',
                            })
                        }else{
                            app.ajax({
                                type:'post',
                                url:app.api('/api/mail/owner/' + para.token),
                                data:{
                                    ticket_id:checkList.join(','),
                                    cs_admin_id:para.staffId,
                                    admin_id:para.user.admin_id,
                                },
                                success:function(res){
                                    if(res.code == 0){
                                        p.urlPara && (location.href = '/'+para.path+'#inbox');
                                        $.comMessage({
                                            type:'success',
                                            text:'指派成功!',
                                        });
                                        getSite($("[name='site_id']").val())
                                    }else{
                                        $.comMessage({
                                            type:'warning',
                                            text:res.msg,
                                        });
                                    }
                                    p.selectStaff.close();
                                    menuRequest({
                                        hoursName:w,
                                        init:true,
                                        tap:true
                                    });
                                }
                            });
                        }
                    })
                });
            });

            //垃圾箱
            $("#trash").on('click',function(){
                var w = $(".site-email").children('.active').prop('id');
                var checkList = [];
                p.urlPara ? checkList.push(p.urlPara) : checkList = p[w].comCheck.checked();
                if(checkList.length <= 0){
                    $.comMessage({
                        type:'prompt',
                        text:'请勾选邮件!',
                    });
                    return;
                }

                $.alert({
                    message:'是否放到垃圾箱?',
                    callback:function(){
                        app.ajax({
                            type:'post',
                            url:app.api('/api/ticket/trashBin/' + para.token),
                            data:{
                                ticket_id:checkList.join(','),
                                admin_id:para.user.admin_id,
                            },
                            success:function(res){
                                if(res.code == 0){
                                    p.urlPara && (location.href = '/'+para.path+'#inbox');
                                    $.comMessage({
                                        type:'success',
                                        text:'操作成功！',
                                    });
                                    getSite($("[name='site_id']").val());
                                    menuRequest({
                                        hoursName:w,
                                        init:true,
                                        tap:true
                                    });
                                }else{
                                    $.comMessage({
                                        type:'warning',
                                        text:res.msg,
                                    });
                                }
                            }
                        });
                    }
                })


            });

            //发送请求回复
            $("#send").on('click',function(){
                var that = $(this);
                var content = p.quill.container.firstChild.innerHTML;
                var len = p.quill.getLength();
                var w = $(".site-email").children('.active').prop('id');

                if(!p.ticket_sn){
                    $.comMessage({
                        type:'prompt',
                        text:'ticket不存在！',
                    });
                    return;
                }
                if(len>1){
                    that.addClass('active-animate');
                    that.prop("disabled",true);
                    insertMessage();
                    //return;
                    app.ajax({
                        type:'post',
                        url:app.api('/api/mail/reply/' + para.token),
                        data:{
                            in_reply_to:p.in_reply_to,
                            receiver_email:p.receiver_email,
                            references_str:p.references_str,
                            reply_p_message_id:p.reply_p_message_id,
                            subject:p.subject,
                            ticket_sn:p.ticket_sn,
                            text_html:content,
                            admin_id:para.user.admin_id,
                            from_account_id:p.account_id
                        },
                        success:function(res){
                            if(res.code == 0){
                                p.urlPara && (location.href = '/'+para.path+'#inbox');
                                $.comMessage({
                                    type:'success',
                                    text:'发送成功！',
                                });
                                menuRequest({
                                    hoursName:w,
                                    init:true,
                                    tap:true
                                });
                                getSite($("[name='site_id']").val());
                                p.quill.container.firstChild.innerHTML = "";
                            }else{
                                $.comMessage({
                                    type:'warning',
                                    text:res.msg,
                                });
                            }
                        },
                        error:function(xml,status){
                            if(status == 'timeout'){
                                $.comMessage({
                                    type:'warning',
                                    text:'网络请求超时！'
                                })
                            }else{
                                $.comMessage({
                                    type:'warning',
                                    text:'网络请求错误！'
                                })
                            }
                        },
                        complete:function(){
                            that.removeClass('active-animate');
                            that.prop("disabled",false);
                        }
                    });

                }else{
                    $.comMessage({
                        type:'prompt',
                        text:'请填写回复文本！',
                    });
                }
            });
            document.onkeydown = function(e) {
                if (13 == e.keyCode && e.ctrlKey) {
                    $("#send").trigger('click');
                }
            };

            //邮件对话
            $("[data-name='menuItem']").on('click','.content-list',function(e){
                if(e.target.nodeName == 'I' || e.target.nodeName == 'INPUT'){
                    return
                }
                var that = $(this);
                var val = that.find('input').val();
                reqTicket(val,that)
            });

            //选择站点邮件数量logo变更事件
            $("#site-header").on('change',"select[name='site_id']",function(){
                var checked = $(this).find("option:checked");
                p.site_id = checked.attr("data-id");
                p.account_id = checked.val();
                com.setCookie("account_id",p.account_id,24);
                var num = checked.attr("data-num");
                var imgUrl = checked.attr("data-img");
                $(".header-num").html(num);
                $(".header-img").find("img").prop('src',imgUrl);

                p.urlPara ? (location.href = '/'+para.path+'#inbox') : location.reload();
                //重新请求菜单数据
                menuBox();
            });

            //搜索结果
            $(".icon-sousuo").on('click',function(){
                searchResult()
            });

            $(".icon-fanhui").on('click',function(){
                var searchObj = $("#search");
                $(this).addClass('hide');
                $("[name='search']").val('');
                searchObj.siblings(".box-list").show();
                searchObj.find("[data-name='com-check']").hide().html("");
                searchObj.hide().removeClass('active');
            })

            $(".order-box").on('click','.list-img',function(e){
                console.log($(this).css('background-image'))
            })

        }

        function searchResult(){
            var val = $("input[name='search']").val();
            if(val){
                app.ajax({
                    type:'post',
                    url:app.api('/api/getSearchTickets/' + para.token),
                    data:{
                        content:val,
                        account_id:p.account_id,
                        page:p.search.page,
                        page_nums:10000
                    },
                    success:function(res){
                        if(res.code == 0){
                            var insertBox = $("#search");
                            var tmpTitle = template('inbox-site-email-title', res.data);
                            var tmpContent = template('inbox-site-email', res.data);
                            insertBox.find("[data-name='title-num']").html(tmpTitle);
                            insertBox.find("[data-name='com-check']").html(tmpContent);

                            insertBox.show().siblings(".box-list").hide();
                            $(".icon-fanhui").removeClass('hide')
                        }else{
                            $.comMessage({
                                type:'prompt',
                                text:res.msg,
                            })
                            $(".icon-fanhui").trigger('click');
                        }
                    }
                });
            }else{
                $.comMessage({
                    type:'prompt',
                    text:'请填写搜索字段！',
                })
            }
        }

        //默认获取站点或者更新总站点数量
        function getSite(paraData){
            app.ajax({
                type:'get',
                url:app.api('/api/getSites/' + para.token),
                data:paraData && {account_id:paraData},
                success:function(res){
                    if(res.code == 0){
                        if(paraData){
                            $(".header-num").html(res.data.data[0].opened_cnt);
                            $("select[name='site_id']").find("option:checked").attr('data-num',res.data.data[0].opened_cnt)
                        }else{
                            var listTmp = template('inbox-site-list', res.data);
                            $("#site-header").html(listTmp);
                            //cookie如果有默认站点
                            if(com.getCookie("account_id")){
                                var d = com.getCookie("account_id");
                                $("select[name='site_id']").find('option').each(function(index,item){
                                    var item = $(item);
                                    if(d == item.attr('value')){
                                        var img = item.attr('data-img');
                                        var num = item.attr('data-num');
                                        item.prop('selected','selected');
                                        $('.header-img').find('img').prop('src',img);
                                        $(".header-num").html(num);
                                        return false;
                                    }
                                })
                            }
                        }
                    }else{
                        $.comMessage({
                            type:'prompt',
                            text:res.type
                        })
                    }
                }
            });
        }

        //邮件对话
        function reqTicket(val,that){

            var loadObj = null;
            app.ajax({
                type:'get',
                url:app.api('/api/ticket/detail/' + para.token + "/" + val),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".mes-content"),
                        background:"rgba(255,255,255,.7)"
                    });
                },
                success:function(res){
                    if(res.code == 0){
                        console.log(res);
                        var dom = template('inbox-talk',res.data);
                        var domHead = template('inbox-talk-head',res.data);
                        $(".mes-content").html(dom);
                        $("#mes-header-box").html(domHead);
                        that && that.addClass('active-info').siblings('.content-list').removeClass('active-info');
                        that && that.closest(".box-list").siblings(".box-list").find('.content-list').removeClass('active-info');

                        p.in_reply_to = res.data.in_reply_to;
                        p.receiver_email = res.data.receiver_email;
                        p.references_str = res.data.references_str;
                        p.reply_p_message_id = res.data.reply_p_message_id;
                        p.subject = res.data.subject;
                        p.ticket_sn = res.data.ticket_sn;
                        erpRequest(res.data.receiver_email)
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            });
        }

        function menuBox(){
            $(".box-list").removeClass('active').find('.list-content').hide();
            //24小时
            menuRequest({
                hoursName:'twentyFour',
                init:true
            });
            //12小时
            menuRequest({
                hoursName:'twelve',
                init:true
            });
            //8
            menuRequest({
                hoursName:'eight',
                init:true
            });
            //now
            menuRequest({
                hoursName:'now',
                init:true
            });
        }
        //请求菜单数据
        function menuRequest(op){
            if(op.hoursName == 'search'){
                return;
                //searchResult()
            }else if(p[op.hoursName].reqSwitch){
                p[op.hoursName].reqSwitch = false;
                var startTime = 0;
                var endTime = 0;
                var name = op.hoursName;
                switch(op.hoursName){
                    case 'twentyFour':
                        startTime = 24;
                        endTime = 0;
                        break;
                    case 'twelve':
                        startTime = 12;
                        endTime = 24;
                        break;
                    case 'eight':
                        startTime = 8;
                        endTime = 12;
                        break;
                    case 'now':
                        startTime = 0;
                        endTime = 8;
                        break;
                }
                app.ajax({
                    type:'post',
                    url:app.api('/api/getTickets/' + para.token),
                    data:{
                        start_time:startTime,
                        end_time:endTime,
                        page:p[name].page,
                        page_nums:p.pageNum,
                        account_id:p.account_id,
                        email_cs_admin_id:para.user.email_cs_admin_id
                    },
                    beforeSend:function(){
                        op.init && (p[name].page = 1);
                    },
                    success:function(res){
                        if(res.code == 0){
                            //renderHoursList(res,$("#"+ name),name,init)
                            var insertBox = $("#"+ name);

                            var tmpTitle = template('inbox-site-email-title', res.data);
                            var tmpContent = template('inbox-site-email', res.data);
                            insertBox.find("[data-name='title-num']").html(tmpTitle);
                            if(op.init){
                                insertBox.find("[data-name='com-check']").html(tmpContent)
                            }else{
                                insertBox.find("[data-name='com-check']").append(tmpContent);
                                p[name].page++;
                            }
                            op.tap && nextData();
                        }else{
                            var hoursObj = $("#"+ name);
                            hoursObj.find('[data-name="title-num"]').html(0);
                            hoursObj.find("[data-name='com-check']").html('');
                            //$("#mes-header-box").html('');
                        }
                    },
                    complete:function(){
                        //状态判断还不完全。
                        p[name].reqSwitch = true;
                    }
                });
            }
        }

        //erp请求
        function erpRequest(email){
            $.ajax({
                type:'post',
                url:'https://api-erp.orderplus.com/api/order/GetOrderDetails',
                data:{
                    email:email
                },
                beforeSend:function(){
                    $(".order-no").addClass('hide');
                },
                success:function(res){
                    if(res.code == 200){
                        console.log(res);
                        var tmp = template('inbox-erp', res);
                        $(".order-box").html(tmp);
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.error
                        });
                        $(".order-box").html("");
                    }
                },
                error:function(xmlObj,status){
                    if(status == 'timeout'){
                        $.comMessage({
                            type:'warning',
                            text:'erp网络请求超时！'
                        })
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:'erp网络请求错误！'
                        })
                    }
                    $(".order-box").html("");
                    $(".order-no").removeClass('hide');
                }
            })
        }

        //请求展开的下一条数据
        function nextData(){
            console.log(12)
            var activeObj = $(".site-email").children('.active');
            //$(".mes-content").html('');
            activeObj.find(".content-list").eq(0).trigger('click');
        }

        //模拟插入对话消息
        function insertMessage(){
            var obj = {
                subject:p.subject,
                list:[
                    {
                        create_time:com.formatDate(new Date().getTime(),'-',':'),
                        is_user:1,
                        text_html:p.quill.container.firstChild.innerHTML,
                    }
                ]
            }
            var dom = template('inbox-talk',obj);
            var contentObj = $(".mes-content");
            contentObj.append(dom);
            contentObj.animate({scrollTop:contentObj[0].scrollHeight},300);
        }


        p.myLayout = $('.layout-inbox').layout({
            livePaneResizing:true,
            spacing_open:5,
            //togglerAlign_open: "right"
            //west__minSize:350
            //west__size:350
            center__minWidth:600,
            west__showOverflowOnHover:true,
            stateManagement__enabled:true, // automatic cookie load & save enabled by default
            showDebugMessages:true, // log and/or display messages from debugging & testing code
            west: {
                closable:false,
                minSize:350,
                size:350
            },
            east:{
                minSize:400,
                size:400,
                slideTrigger_open:"mouseover",
                spacing_closed:0
            },
            center__paneSelector:".ui-layout-center",
            east__paneSelector:	".ui-layout-east",
            west__paneSelector:	".ui-layout-west",
            contentSelector:".mes-child-box",
            center__childOptions:{
                north__paneSelector:	".child-north",
                center__paneSelector:	".child-center",
                resizerTip:'调节',
                livePaneResizing:true,
                spacing_open:5,
                closable:false,
                north__minSize:300,
                north__size:400,
                center__minHeight:150,
                center__size:200
            }
        });

        //app.dynamicLoadJs(p.src,"inbox",function(){
        p.quill = new Quill('#editor-container', {
            modules: {
                toolbar: [
                    [{ header: [1, 2,3,4, false] }],
                    ['bold', 'italic', 'underline'],
                    ['image', /*'code-block'*/]
                ],
                //imageDrop: true,
            },
            placeholder: 'Compose an epic...',
            theme: 'snow'  // or 'bubble'
        });

        $('.layout-inbox').css('opacity','1');
        $(".fold").on('click',function(){
            var isHidden = $(".ui-layout-east").is(":hidden");
            isHidden ? $(this).addClass('fold-z') : $(this).removeClass('fold-z');
        })
        p.myLayout.bindButton('.fold', 'toggle', 'east');
        $("#btnReset").click(function(){
            //myLayout.loadState(stateResetSettings, true)
        });
        //})


    });



</script>



<!--
    let stateResetSettings = {
        north__size:		"auto"
        ,	north__initClosed:	false
        ,	north__initHidden:	false
        ,	south__size:		"auto"
        ,	south__initClosed:	false
        ,	south__initHidden:	false
        ,	west__size:			200
        ,	west__initClosed:	false
        ,	west__initHidden:	false
        ,	east__size:			300
        ,	east__initClosed:	false
        ,	east__initHidden:	false
    };

-->